import {Message} from "element-ui";

export default ({app,store}) => {
  app.router.beforeEach((to,form,nuxt) => {
    if(to.path !== '/login'){
      if(store.state.user.currentUser.UserID){
        nuxt()
      }else{
        let user = window.localStorage.getItem('currentUser')
        if(user){
          store.commit('user/setCurrentUser',JSON.parse(user))
          nuxt()
        }else{
          Message.warning('未登录！')
          nuxt('/login')
        }
      }
      //获取localStore里面保存的路由历史信息
      let routes = window.localStorage.getItem('routeTag')
      console.log(routes)
      if(!store.state.base.routes.length && routes){
        store.commit('base/setRoute',JSON.parse(routes))
      }
    }else{
      nuxt()
    }
  })
}
